<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script>
        let str = '2018-03-20';
        let reg = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/;

        // 03/20/2018 替换
        // str = str.replace(reg, '$<year>/$<month>/$<day>');

        str = str.replace(reg, (...args) => {
            //console.log(args);
            let {
                year,
                month,
                day
            } = args[args.length - 1];
            return `${day}/${month}/${year}`;
        });

        console.log(str);
    </script>
</head>

<body>

</body>

</html>